import type { DisableDto, DisableRes, PutDto, PutMutiDto, PutMutiRes, PutRes } from "~/rest";

import { Gateway, getGateway } from "@/droplet-bus/core.define";

import { RiverStockGateway } from "@/river-stock/core.define";
import { StockNode, StockNodeLink } from "@/river-stock/schema.node";

export const StockNodeGateway: Gateway = getGateway(RiverStockGateway, "river_stock_node");
export type putStockNodeDto = PutMutiDto<StockNode>;
export type putStockNodeChildDto = PutMutiDto<StockNode> & { parentId: StockNode["id"] };
export type patchStockNodeDto = PutDto<StockNode>;
export type deleteStockNodeDto = DisableDto;

export interface StockNodeInterfaceWithGrant<T> {
  /** 修改节点信息 */
  put(dto: T & putStockNodeDto): Promise<PutMutiRes<StockNode>>;

  /** 创建子节点 */
  putChildSync(dto: T & putStockNodeChildDto): Promise<PutMutiRes<StockNode>>;

  /** 重新计算节点上的常规库存 */
  patch(dto: T & patchStockNodeDto): Promise<null>;

  /** 删除节点及其子节点
   * @tipA 如果包含了冷卷库存，就无法继续删除
   */
  delete(dto: T & deleteStockNodeDto): Promise<DisableRes>;

  /** 查询库存队列 */
  getTask(dto: T): Promise<{ count: number }>;
}

export const StockNodeLinkGateway: Gateway = getGateway(RiverStockGateway, "river_stock_node_link");
export type deleteStockNodeLinkDto = { linkId: StockNodeLink["id"] };

export interface StockNodeLinkInterfaceWithGrant<T> {
  /** 解除（订单集合 && 库存节点）这个关联 */
  delete(dto: T & deleteStockNodeLinkDto): Promise<DisableRes>;
}
